package com.szhuang.mobilesafe.tools;

import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

/**
 * Created by szhuang on 2015/3/29.
 */
public class ServiceUtils {

    public static boolean isServiceRunning(Context context, String serviceName) {

        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> infos = activityManager.getRunningServices(100);
        for (ActivityManager.RunningServiceInfo info : infos) {
            String name = info.service.getClassName();
            if (serviceName.equals(name)) {
                return true;
            }
        }
        return false;
    }
}
